#include "stddef.h"
#include "string.h"
#include "cpuid.h"

size_t strlen(const char * const str)
{
	size_t tmp;

	tmp = (size_t)str;
		
	asm(".strlen_start:				"
		"    cmpb $0, 0(%1);		"
		"	 jz .strlen_done;		"
		"    cmpb $0, 1(%1);		"
		"	 jz .strlen_1;			"
		"    cmpb $0, 2(%1);		"
		"	 jz .strlen_2;			"
		"    cmpb $0, 3(%1);		"
		"	 jz .strlen_3;			"
		"    cmpb $0, 4(%1);		"
		"	 jz .strlen_4;			"
		"    cmpb $0, 5(%1);		"
		"	 jz .strlen_5;			"
		"    cmpb $0, 6(%1);		"
		"	 jz .strlen_6;			"
		"    cmpb $0, 7(%1);		"
		"	 jz .strlen_7;			"
		/* if no 0s were found, add 8 and start again */
		"	 add $8, %1;			"
		"	 jmp .strlen_start;		"
		/* here are all the expanded functions that get called once a 0 is found */
		".strlen_1:					"
		"	 inc %1;    			"
		"	 jmp .strlen_done;		"
		".strlen_2:					"
		"	 add $2, %1;			"
		"	 jmp .strlen_done;		"
		".strlen_3:					"
		"	 add $3, %1;			"
		"	 jmp .strlen_done;		"
		".strlen_4:					"
		"	 add $4, %1;			"
		"	 jmp .strlen_done;		"
		".strlen_5:					"
		"	 add $5, %1;			"
		"	 jmp .strlen_done;		"
		".strlen_6:					"
		"	 add $6, %1;			"
		"	 jmp .strlen_done;		"
		".strlen_7:					"
		"	 add $7, %1;			"
		/* output the current value, and exit. */
		".strlen_done:				"
		"	mov %1, %0;				"
		:"=r"(tmp):"0"(tmp));

	return tmp - (size_t)str;
}


